--- jupytext: formats: ipynb,md:myst text_representation: extension: .md format_name: myst format_version: 0.13 jupytext_version: 1.14.5 kernelspec: display_name: Python 3 (ipykernel) language: python name: python3 --- +++ {"id": "a3o1EnPLWeAv"} (tutorial_3)= # Single subject Author: Nicolas Legrand Adapted from the tutorial proposed by the HMeta-d toolbox: https://github.com/metacoglab/HMeta-d/tree/master/CPC_metacog_tutorial ```{code-cell} ipython3 :tags: [hide-cell] %%capture import sys if 'google.colab' in sys.modules: ! pip install metadpy ``` ```{code-cell} ipython3 :id: uSC4P5ghWTZb import arviz as az import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns from metadpy.bayesian import hmetad sns.set_context("talk") ``` ```{code-cell} ipython3 :id: v8xhAXePWm2Y # Create responses data nR_S1 = np.array([52, 32, 35, 37, 26, 12, 4, 2]) nR_S2 = np.array([2, 5, 15, 22, 33, 38, 40, 45]) ``` +++ {"id": "ZOop3bjebxbZ"} ## Using metadpy ```{code-cell} ipython3 --- colab: base_uri: https://localhost:8080/ height: 118 referenced_widgets: [48a76ae7649b48f9a0a85ccc5751815d, 21b2283e56ee49f5a0142808dacbe6a9, f1103196b06642c8ba127ab3784a0fda, e293ba5b914646b58817190af25fb921, a11181a9d3bc4a74b795c1099125ddaa, fbb738761edf4c5e8a31271931243fc8, bade777d33fb4651a70fbf97e059fbd0, 34652852c7ec4a9aa50f3411d378c7f0, cbe8740b7a1841e6be7fb4041581ef5e, 4f1d2dba668f40ce8c3fea52ffd68600, 746da93bd5fb4fd0ab091ca40ce68762, f0e23502e0964dc08189ff00e9132196, b358e7faba4046dcaf4c70d2a8ab2982, c945cf1be9a04cd780d4b1929ebc0fa7, 2d73190fef28427088ae5c566e333ad8, f1c2f8b5a53c442fad4c719346978113] id: zpPdxFLiWsaW outputId: bcf46df4-7be3-4381-e167-548b0a4f971f --- model, traces = hmetad(nR_S1=nR_S1, nR_S2=nR_S2) ``` +++ {"id": "wcB7amGfbz8e"} ## Using HMeta-d The results were generated by the `example_metad_indiv.R` file. ```{code-cell} ipython3 :id: RA4wULVlb8Gf hmetad_df = pd.read_csv("./hmetad/metad_indiv.txt", sep="\t") ``` +++ {"id": "iBFWERvGiPrO"} ## Comparison ```{code-cell} ipython3 --- colab: base_uri: https://localhost:8080/ height: 568 id: 5JllhVsgcauL outputId: e2473dd6-97ac-4c10-8eeb-83087cca5c1e --- _, axs = plt.subplots(2, 1, figsize=(8, 8), sharex=True) az.plot_posterior(hmetad_df.meta_d.to_numpy(), ax=axs[0]) az.plot_posterior(traces, var_names=["meta_d"], ax=axs[1]) axs[0].set_ylabel("HMeta-d") axs[1].set_ylabel("metadpy") plt.tight_layout() ``` ```{code-cell} ipython3 ```